const Visitor = require('../models/Visitor');

// 更新last_chat_type字段
exports.updateLastChatType = async (req, res) => {
    const { uuid, last_chat_type } = req.body;
    if (!uuid || !last_chat_type) {
        return res.status(400).json({ success: false, message: '缺少uuid或last_chat_type' });
    }
    try {
        const visitor = await Visitor.findByPk(uuid);
        if (!visitor) {
            return res.status(404).json({ success: false, message: '用户未找到' });
        }
        visitor.last_chat_type = last_chat_type;
        await visitor.save();
        return res.status(200).json({ success: true, message: 'last_chat_type更新成功', data: { uuid, last_chat_type } });
    } catch (error) {
        return res.status(500).json({ success: false, message: '服务器错误', error: error.message });
    }
};

// 根据uuid获取last_chat_type字段
exports.getLastChatType = async (req, res) => {
    const { uuid } = req.query;
    if (!uuid) {
        return res.status(400).json({ success: false, message: '缺少uuid' });
    }
    try {
        const visitor = await Visitor.findByPk(uuid);
        if (!visitor) {
            return res.status(404).json({ success: false, message: '用户未找到' });
        }
        return res.status(200).json({ success: true, last_chat_type: visitor.last_chat_type });
    } catch (error) {
        return res.status(500).json({ success: false, message: '服务器错误', error: error.message });
    }
}; 